﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ControlAccessUser.Bussiness;
using ControlAccessUser.Model;

namespace ControlAccessUser.Presenter
{
    public class PresenterSearchUser
    {
        ISearchUserView View;

        public PresenterSearchUser(ISearchUserView View)
        {
            this.View = View;
        }

        public void SearchUserByRelativeFields()
        {            
            View.UsersFound = ManagerUser.SearchUserByRelativeFields(new User() { UserId = View.UserIdSearch, UserFirstName = View.UserFirstNameSearch, UserLastName = View.UserLastNameSearch, UserName = View.UserNameSearch });
        }

        public void SearhcUserByUserName()
        {
            View.UsersFound = ManagerUser.SearhcUserByUserName(new User() { UserId = View.UserIdSearch, UserFirstName = View.UserFirstNameSearch, UserLastName = View.UserLastNameSearch, UserName = View.UserNameSearch });
        }

        public void SearhcUserByUserId()
        {
            View.UsersFound = ManagerUser.SearchUserByUserId(new User() { UserId = View.UserIdSearch, UserFirstName = View.UserFirstNameSearch, UserLastName = View.UserLastNameSearch, UserName = View.UserNameSearch });
        }

        public void GoDetailsLogins()
        {
            View.GoUserSelected(View.DataSelectedUser);
        }

        public void LogoutSelectedUser()
        {
            if (View.UserLogged==View.DataSelectedUser)
            {
                View.ErrorMessage = Message.LogoutByManagerError;
            }
            else if (View.DataSelectedUser != null)
            {
                if (View.UserReallyGoOut)
                {
                    try
                    {
                        ManagerUser.RegisterLogout(View.DataSelectedUser);
                    }
                    catch (Exception err)
                    {
                        View.SystemMessage = err.Message;
                    }
                }
            }
            else
            {
                View.SystemMessage = Message.ErrorRequiredSelectedUser;
            }
        }
    }
}
